module DrunkenMaster
  class WidgetCallbackHandler
      def initialize root_widget_class
      @module = Magic.module_of(root_widget_class)
    end
    
    def execute context
#      widget =
#      @module.const_get(
#        Util::CamelCase.to(context.tail[0])
#      ).new
      class_name = context.tail[0].split('-').collect{ |name|
          Util::CamelCase.to(name)
        }.join('::')
        
      widget_class = Magic.to_const(class_name)
      widget = widget_class.new
      widget.context = context
      context.tail = context.tail[1,:last]
      widget.execute(context)
      #context.response.body = widget.render.join()
      #context.tail = context.tail[1,:last]
    end
  end
end